class Solution {
public:
    int maxNumOfMarkedIndices(vector<int>& nums)
    {
        int n = nums.size();
        ranges::sort(nums);
        int ans = 0;
        for (int left = 0, right = n / 2; left < n / 2 && right < n; left++, right++)
        {
            if (nums[left] * 2 <= nums[right])
                ans += 2;
            else
            {
                while (right < n && 2 * nums[left] > nums[right]) right++;
                if (right == n)
                    break;
                ans += 2;
            }
        }
        return ans;
    }
};